#include "message.hpp"
#include "net.hpp"

void onMessage(const bitrpc::BaseConnection::ptr &conn, bitrpc::BaseMessage::ptr &msg)
{
    std::string body = msg->serialize();
    std::cout << body << std::endl;

    auto rpc_res = bitrpc::MessageFactory::create<bitrpc::RpcResponse>();
    rpc_res->setId("11111");
    rpc_res->setMType(bitrpc::MType::RSP_RPC);
    rpc_res->setRCode(bitrpc::RCode::RCODE_OK);
    rpc_res->setResult(33);

    conn->send(rpc_res);
}

int main()
{
    auto server = bitrpc::ServerFactory::create(9090);
    server->setMessageCallback(onMessage);
    server->start();

    return 0;
}